import React from "react";
import {IGridCellRenderParam} from "./grid_type";
import Grid from "./grid";
import {DatePicker} from "antd";
import {moment} from "../../factory";

interface DatePickerEditorProp extends IGridCellRenderParam {
    $context: any

    colDef: {
        /**
         * 渲染函数
         */
        data: any[]
    }

    grid: Grid
}

interface DatePickerEditorState {
    value: any
}

export default class DatePickerEditor extends React.Component<DatePickerEditorProp, DatePickerEditorState> {

    constructor(props: DatePickerEditorProp) {
        super(props);

        this.state = {
            value: props.value && moment(parseInt(props.value))
        }
    }

    private dateFormat:string = 'YYYY-MM-DD';

    handleChange(date: any, dateString: string) {
        this.setState({
            value: date
        })
    }

    render() {
        return (
            <DatePicker
                defaultValue={this.state.value}
                format={this.dateFormat}
                style={{width: '100%'}}
                onChange={this.handleChange.bind(this)}
            />
        );
    }

    getValue(): any {
        return this.state.value?.valueOf()?.toString()
    }
}